#pragma once
#pragma comment(lib, "advapi32.lib")
#pragma comment(lib, "user32.lib")

//#include <tlhelp32.h>
#include <windows.h>
#include <vector>
#include <string>
#include <iostream>
#using<system.dll>


namespace TempusGUI {
	using namespace std;
	using namespace System;
	using namespace System::Runtime::InteropServices;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Collections::Specialized;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for Form1
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		
		[DllImport("user32")]
		static bool AnimateWindow(IntPtr hwnd, int time, int flags);
		Form1(void)
		{
			pages = gcnew StringCollection;
			stringCollection = gcnew cli::array<System::String ^>(10){
			L"show",L"add",
				L"delete",
				L"edit",
				L"date",
				L"time",L"location",L"exit",L"priority",L"time"};
			InitializeComponent();
			mainLabel = "";
			subLabel = "";
			indexLastSpace = 0;
			spaceCount = 0;
			backSlashCount = 2;
			currentPage = 0;
			
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::TextBox^  textBox1;
	private: int backSlashCount;
			 int currentPage;
	private: int spaceCount, indexLastSpace;
	private: StringCollection ^ pages;
			 String ^ mainLabel, ^ subLabel;
	private: bool isLastBackslash, dragging, firstFocus;
	private: Point pointClicked;
	private: cli::array<System::String ^> ^ stringCollection;
	protected: 

	private: System::Windows::Forms::Label^  label1;

	private: System::ComponentModel::BackgroundWorker^  backgroundWorker1;
	private: System::Windows::Forms::NotifyIcon^  notifyIcon1;
	private: System::Windows::Forms::ContextMenuStrip^  contextMenuStrip1;
	private: System::Windows::Forms::ToolStripMenuItem^  restoreToolStripMenuItem;
	private: System::Windows::Forms::ToolStripMenuItem^  exitToolStripMenuItem;

	private: System::Windows::Forms::Panel^  panel1;
	private: System::Windows::Forms::Button^  button2;
	private: System::Windows::Forms::Button^  button1;
	private: System::Windows::Forms::Label^  label3;
	private: System::Windows::Forms::Panel^  panel2;
	private: System::Windows::Forms::Panel^  panel3;
	private: System::Windows::Forms::TextBox^  textBox2;
	private: System::Windows::Forms::Panel^  panel4;
	private: System::Windows::Forms::Label^  label4;
	private: System::Windows::Forms::Label^  label2;


	private: System::ComponentModel::IContainer^  components;

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>


#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->components = (gcnew System::ComponentModel::Container());
			System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->backgroundWorker1 = (gcnew System::ComponentModel::BackgroundWorker());
			this->notifyIcon1 = (gcnew System::Windows::Forms::NotifyIcon(this->components));
			this->contextMenuStrip1 = (gcnew System::Windows::Forms::ContextMenuStrip(this->components));
			this->restoreToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->exitToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->panel1 = (gcnew System::Windows::Forms::Panel());
			this->label3 = (gcnew System::Windows::Forms::Label());
			this->button2 = (gcnew System::Windows::Forms::Button());
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->panel2 = (gcnew System::Windows::Forms::Panel());
			this->panel3 = (gcnew System::Windows::Forms::Panel());
			this->textBox2 = (gcnew System::Windows::Forms::TextBox());
			this->panel4 = (gcnew System::Windows::Forms::Panel());
			this->label4 = (gcnew System::Windows::Forms::Label());
			this->label2 = (gcnew System::Windows::Forms::Label());
			this->contextMenuStrip1->SuspendLayout();
			this->panel1->SuspendLayout();
			this->panel2->SuspendLayout();
			this->panel3->SuspendLayout();
			this->panel4->SuspendLayout();
			this->SuspendLayout();
			// 
			// textBox1
			// 
			this->textBox1->BackColor = System::Drawing::SystemColors::Info;
			this->textBox1->BorderStyle = System::Windows::Forms::BorderStyle::None;
			this->textBox1->Font = (gcnew System::Drawing::Font(L"Comic Sans MS", 10.2F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->textBox1->Location = System::Drawing::Point(15, 16);
			this->textBox1->Multiline = true;
			this->textBox1->Name = L"textBox1";
			this->textBox1->ReadOnly = true;
			this->textBox1->Size = System::Drawing::Size(372, 272);
			this->textBox1->TabIndex = 0;
			this->textBox1->TextChanged += gcnew System::EventHandler(this, &Form1::textBox1_TextChanged);
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->BackColor = System::Drawing::Color::Transparent;
			this->label1->Font = (gcnew System::Drawing::Font(L"Comic Sans MS", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->label1->ForeColor = System::Drawing::Color::MidnightBlue;
			this->label1->Location = System::Drawing::Point(52, 74);
			this->label1->MaximumSize = System::Drawing::Size(78, 29);
			this->label1->MinimumSize = System::Drawing::Size(78, 29);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(78, 29);
			this->label1->TabIndex = 2;
			this->label1->Text = L"Output";
			// 
			// backgroundWorker1
			// 
			this->backgroundWorker1->DoWork += gcnew System::ComponentModel::DoWorkEventHandler(this, &Form1::backgroundWorker1_DoWork);
			// 
			// notifyIcon1
			// 
			this->notifyIcon1->BalloonTipText = L"The program has minimized";
			this->notifyIcon1->BalloonTipTitle = L"Tempus GUI";
			this->notifyIcon1->ContextMenuStrip = this->contextMenuStrip1;
			this->notifyIcon1->Icon = (cli::safe_cast<System::Drawing::Icon^  >(resources->GetObject(L"notifyIcon1.Icon")));
			this->notifyIcon1->Text = L"notifyIcon1";
			this->notifyIcon1->Visible = true;
			this->notifyIcon1->DoubleClick += gcnew System::EventHandler(this, &Form1::notifyIcon1_DoubleClick);
			// 
			// contextMenuStrip1
			// 
			this->contextMenuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(2) {this->restoreToolStripMenuItem, 
				this->exitToolStripMenuItem});
			this->contextMenuStrip1->Name = L"contextMenuStrip1";
			this->contextMenuStrip1->Size = System::Drawing::Size(129, 52);
			this->contextMenuStrip1->Opening += gcnew System::ComponentModel::CancelEventHandler(this, &Form1::contextMenuStrip1_Opening);
			// 
			// restoreToolStripMenuItem
			// 
			this->restoreToolStripMenuItem->Name = L"restoreToolStripMenuItem";
			this->restoreToolStripMenuItem->Size = System::Drawing::Size(128, 24);
			this->restoreToolStripMenuItem->Text = L"Restore";
			this->restoreToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::restoreToolStripMenuItem_Click);
			// 
			// exitToolStripMenuItem
			// 
			this->exitToolStripMenuItem->Name = L"exitToolStripMenuItem";
			this->exitToolStripMenuItem->Size = System::Drawing::Size(128, 24);
			this->exitToolStripMenuItem->Text = L"Exit";
			this->exitToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::exitToolStripMenuItem_Click);
			// 
			// panel1
			// 
			this->panel1->BackgroundImage = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"panel1.BackgroundImage")));
			this->panel1->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Stretch;
			this->panel1->Controls->Add(this->label3);
			this->panel1->Controls->Add(this->button2);
			this->panel1->Controls->Add(this->button1);
			this->panel1->Location = System::Drawing::Point(0, -1);
			this->panel1->Name = L"panel1";
			this->panel1->Size = System::Drawing::Size(495, 48);
			this->panel1->TabIndex = 5;
			this->panel1->DragDrop += gcnew System::Windows::Forms::DragEventHandler(this, &Form1::panel1_DragDrop);
			this->panel1->MouseDown += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::panel1_MouseDown);
			this->panel1->MouseMove += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::panel1_MouseMove);
			this->panel1->MouseUp += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::panel1_MouseUp);
			// 
			// label3
			// 
			this->label3->AutoSize = true;
			this->label3->BackColor = System::Drawing::Color::Transparent;
			this->label3->Font = (gcnew System::Drawing::Font(L"Forte", 18, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->label3->ForeColor = System::Drawing::Color::White;
			this->label3->Location = System::Drawing::Point(176, 7);
			this->label3->Name = L"label3";
			this->label3->Size = System::Drawing::Size(117, 32);
			this->label3->TabIndex = 2;
			this->label3->Text = L"Tempus";
			// 
			// button2
			// 
			this->button2->BackColor = System::Drawing::Color::Transparent;
			this->button2->FlatAppearance->BorderSize = 0;
			this->button2->FlatStyle = System::Windows::Forms::FlatStyle::Flat;
			this->button2->Font = (gcnew System::Drawing::Font(L"Mistral", 18, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->button2->ForeColor = System::Drawing::Color::White;
			this->button2->Location = System::Drawing::Point(449, 5);
			this->button2->Name = L"button2";
			this->button2->Size = System::Drawing::Size(43, 42);
			this->button2->TabIndex = 1;
			this->button2->Text = L"X";
			this->button2->UseVisualStyleBackColor = false;
			this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
			// 
			// button1
			// 
			this->button1->BackColor = System::Drawing::Color::Transparent;
			this->button1->FlatAppearance->BorderColor = System::Drawing::Color::Maroon;
			this->button1->FlatAppearance->BorderSize = 0;
			this->button1->FlatStyle = System::Windows::Forms::FlatStyle::Flat;
			this->button1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 18, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->button1->ForeColor = System::Drawing::Color::White;
			this->button1->Location = System::Drawing::Point(400, 3);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(43, 42);
			this->button1->TabIndex = 0;
			this->button1->Text = L"-";
			this->button1->UseVisualStyleBackColor = false;
			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// panel2
			// 
			this->panel2->BackgroundImage = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"panel2.BackgroundImage")));
			this->panel2->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Stretch;
			this->panel2->Controls->Add(this->textBox1);
			this->panel2->Location = System::Drawing::Point(42, 109);
			this->panel2->Name = L"panel2";
			this->panel2->Size = System::Drawing::Size(401, 306);
			this->panel2->TabIndex = 6;
			// 
			// panel3
			// 
			this->panel3->BackgroundImage = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"panel3.BackgroundImage")));
			this->panel3->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Stretch;
			this->panel3->Controls->Add(this->textBox2);
			this->panel3->Location = System::Drawing::Point(42, 449);
			this->panel3->Name = L"panel3";
			this->panel3->Size = System::Drawing::Size(401, 58);
			this->panel3->TabIndex = 7;
			// 
			// textBox2
			// 
			this->textBox2->AutoCompleteMode = System::Windows::Forms::AutoCompleteMode::Append;
			this->textBox2->AutoCompleteSource = System::Windows::Forms::AutoCompleteSource::CustomSource;
			this->textBox2->BackColor = System::Drawing::SystemColors::Info;
			this->textBox2->BorderStyle = System::Windows::Forms::BorderStyle::None;
			this->textBox2->Font = (gcnew System::Drawing::Font(L"Comic Sans MS", 10.2F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->textBox2->ForeColor = System::Drawing::SystemColors::ControlDarkDark;
			this->textBox2->Location = System::Drawing::Point(23, 18);
			this->textBox2->Name = L"textBox2";
			this->textBox2->Size = System::Drawing::Size(353, 24);
			this->textBox2->TabIndex = 0;
			this->textBox2->Text = L"//              Enter Command Here";
			this->textBox2->Click += gcnew System::EventHandler(this, &Form1::textBox2_Click);
			this->textBox2->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &Form1::textBox2_KeyDown);
			this->textBox2->KeyUp += gcnew System::Windows::Forms::KeyEventHandler(this, &Form1::textBox2_KeyUp);
			this->textBox2->PreviewKeyDown += gcnew System::Windows::Forms::PreviewKeyDownEventHandler(this, &Form1::textBox2_PreviewKeyDown);
			// 
			// panel4
			// 
			this->panel4->BackgroundImage = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"panel4.BackgroundImage")));
			this->panel4->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Stretch;
			this->panel4->Controls->Add(this->label4);
			this->panel4->Location = System::Drawing::Point(0, 553);
			this->panel4->Name = L"panel4";
			this->panel4->Size = System::Drawing::Size(491, 52);
			this->panel4->TabIndex = 8;
			// 
			// label4
			// 
			this->label4->AutoSize = true;
			this->label4->BackColor = System::Drawing::Color::Transparent;
			this->label4->Font = (gcnew System::Drawing::Font(L"Comic Sans MS", 7.8F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->label4->ForeColor = System::Drawing::SystemColors::Window;
			this->label4->Location = System::Drawing::Point(28, 10);
			this->label4->Name = L"label4";
			this->label4->Size = System::Drawing::Size(0, 19);
			this->label4->TabIndex = 0;
			this->label4->Click += gcnew System::EventHandler(this, &Form1::label4_Click);
			// 
			// label2
			// 
			this->label2->AutoSize = true;
			this->label2->Font = (gcnew System::Drawing::Font(L"Comic Sans MS", 7.8F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->label2->Location = System::Drawing::Point(372, 418);
			this->label2->Name = L"label2";
			this->label2->Size = System::Drawing::Size(0, 19);
			this->label2->TabIndex = 9;
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->BackColor = System::Drawing::SystemColors::Info;
			this->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Stretch;
			this->ClientSize = System::Drawing::Size(490, 605);
			this->Controls->Add(this->label2);
			this->Controls->Add(this->panel4);
			this->Controls->Add(this->panel2);
			this->Controls->Add(this->panel1);
			this->Controls->Add(this->label1);
			this->Controls->Add(this->panel3);
			this->Name = L"Form1";
			this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
			this->Text = L"Form1";
			this->FormClosing += gcnew System::Windows::Forms::FormClosingEventHandler(this, &Form1::Form1_FormClosing);
			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
			this->Shown += gcnew System::EventHandler(this, &Form1::Form1_Shown);
			this->SizeChanged += gcnew System::EventHandler(this, &Form1::Form1_SizeChanged);
			this->MouseDown += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::Form1_MouseDown);
			this->contextMenuStrip1->ResumeLayout(false);
			this->panel1->ResumeLayout(false);
			this->panel1->PerformLayout();
			this->panel2->ResumeLayout(false);
			this->panel2->PerformLayout();
			this->panel3->ResumeLayout(false);
			this->panel3->PerformLayout();
			this->panel4->ResumeLayout(false);
			this->panel4->PerformLayout();
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	private: System::Void label2_Click(System::Object^  sender, System::EventArgs^  e) {
			 }
			 System::Void label2Text( int pageNo )
			 {
				 label2->Text = "Page : " + pageNo + "/" + pages->Count;
			 }
			 String ^ convertToGUIString( std::string cliString )
			 {
				 String ^ convertedString = gcnew String( cliString.c_str() );
				 return convertedString;
			 }

			 std::string convertToCliString( String ^ guiString)
			 {
				 std::string convertedString;
				 const char* chars = (const char*)(Marshal::StringToHGlobalAnsi(guiString)).ToPointer();
				 convertedString = chars;
				 Marshal::FreeHGlobal(IntPtr((void*)chars));
				 return convertedString;
			 }

	private: System::Void displaySample()
			 {
				 int i;
				 for ( i = 0; i < 50; i++)
				 {
					 textBox1->Text += i ;
					 for (int j = 0; j<38;j++)
					 {
						 textBox1->Text += "a";
					 }
					 textBox1->Text += "b" + Environment::NewLine;
				 }
				 displayText(pages);
				 label2Text(1);
			 }
	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
				
				// AnimateWindow(this->Handle, 1000, AW_VER_NEGATIVE | AW_SLIDE);
				// this->Show();
				 
				 displaySample();
				 backgroundWorker1->RunWorkerAsync();
				 this->ControlBox = false;
				 this->Text = "";//String::Empty;
			 }

private: System::Void backgroundWorker1_DoWork(System::Object^  sender, System::ComponentModel::DoWorkEventArgs^  e) {
		
		if (RegisterHotKey(NULL,1,MOD_ALT | MOD_CONTROL,0x53))  //0x53 is 's'
		 { 
			 //MessageBox::Show("Registered HotKey - ALT + CTRL + S");
		 }
		 MSG msg = {0};
		 while (GetMessage(&msg, NULL, 0, 0) == 1)
		 {
			 if (msg.message == WM_HOTKEY)
			 {
				 this->Show();
				 this->WindowState = FormWindowState::Normal;
				 textBoxFocus();
			 }
		
		 }
	}
private: System::Void textBoxFocus()
		 {
				textBox2->Focus();
				textBox2->SelectionStart = 2;
		 }
private: System::Void Form1_SizeChanged(System::Object^  sender, System::EventArgs^  e) {
			 
		 }
private: System::Void contextMenuStrip1_Opening(System::Object^  sender, System::ComponentModel::CancelEventArgs^  e) {
		 }
private: System::Void exitToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
			 this->Close();
		 }
private: System::Void restoreToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
			
			notifyIcon1->Visible = false;
			this->Show();
			this->WindowState = FormWindowState::Normal;
			textBoxFocus();
		 }

private: System::Void Form1_FormClosing(System::Object^  sender, System::Windows::Forms::FormClosingEventArgs^  e) {
			
		 }
private: System::Void notifyIcon1_DoubleClick(System::Object^  sender, System::EventArgs^  e) {

			 notifyIcon1->Visible = false;
			 this->Show();
			 this->WindowState =  FormWindowState::Normal;
			 textBoxFocus();
		 }
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
				this->WindowState = FormWindowState::Minimized;
		 }
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {

			 if( this->WindowState == FormWindowState::Normal || this->WindowState == FormWindowState::Maximized )
			 {
				 this->WindowState =  FormWindowState::Minimized;
				 notifyIcon1->Visible = true;
				 notifyIcon1->ShowBalloonTip(500);
				 this->Hide();
			 }
		 }
private: System::Void panel1_DragDrop(System::Object^  sender, System::Windows::Forms::DragEventArgs^  e) {
			 
		 }
private: System::Void Form1_MouseDown(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
			
		 }
private: System::Void panel1_MouseMove(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
			 if (dragging){
				 Point pointMoveTo;
				 Point temp = Point(e->X,e->Y);
				 pointMoveTo = this->PointToScreen(temp);

				 pointMoveTo.Offset(-pointClicked.X, -pointClicked.Y);

				 this->Location = pointMoveTo;
			 } 
		 }
private: System::Void panel1_MouseDown(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
			 if (e->Button ==  System::Windows::Forms::MouseButtons::Left )
			 {
				 dragging = true;
				 pointClicked = Point(e->X, e->Y);
			 }
			 else
			 {
				 dragging = false;
			 }
		 }
private: System::Void panel1_MouseUp(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
			 dragging = false;
		 }
private: System::Void restoreFontSettings()  {

			 this->textBox2->Font = (gcnew System::Drawing::Font(L"Comic Sans MS", 10.2F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				 static_cast<System::Byte>(0)));
			 this->textBox2->ForeColor = System::Drawing::SystemColors::WindowText;
			 this->textBox2->TextAlign = System::Windows::Forms::HorizontalAlignment::Left;

		 }
private: System::Void newlineFontSettings()
		 {
			 this->textBox2->Font = (gcnew System::Drawing::Font(L"Comic Sans MS", 10.2F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				 static_cast<System::Byte>(0)));
			 this->textBox2->ForeColor = System::Drawing::SystemColors::ControlDarkDark;
			 this->textBox2->Text = L"//              Enter Command Here";
			 textBox2->SelectionStart = 2;
		 }
private: System::Void enableAutoComplete()
		 {
			 this->textBox2->AutoCompleteMode = AutoCompleteMode::Append;
			 this->textBox2->AutoCompleteSource = System::Windows::Forms::AutoCompleteSource::CustomSource;
		 }
private: System::Void disableAutoComplete()
		 {
			 this->textBox2->AutoCompleteMode = AutoCompleteMode::None;
		 }
private: System::Void textBox2_KeyUp(System::Object^  sender, System::Windows::Forms::KeyEventArgs^  e) {
			 String ^ t = textBox2->Text;
			 int length = textBox2->SelectionStart;
			 if (e->KeyCode == Keys::Back && ( textBox2->Text->Substring(0,textBox2->SelectionStart)->Equals("//")))
			 {
				 newlineFontSettings();
				 textBox2->Text = "//              Enter Command Here";
				 textBox2->SelectionStart = 2;
				 firstFocus = true;
				 textBox2->AutoCompleteCustomSource->Clear();
				 textBox2->AutoCompleteCustomSource->AddRange(stringCollection);
				 textBox2->AutoCompleteSource = AutoCompleteSource::CustomSource;
				 resetParameters();
					 return;
			 }
			 if(firstFocus)
			 {
				 int i;
				 restoreFontSettings();
				 String ^ temp = textBox2->Text->Substring(2,1);
				 textBox2->Text = "";
				 
				 firstFocus = false;
				 textBox2->Text = "//";
				 cli::array<System::String ^> ^ tempCollection = gcnew cli::array<System::String ^>(10);
				 for ( i = 0; i < 10; i++)
				 {
					 tempCollection[i] = "//" +  stringCollection[i];
				 }

				 // getLineCount();
				 textBox2->Text += temp;
				 this->textBox2->AutoCompleteCustomSource->AddRange(tempCollection);
				 enableAutoComplete();
				 textBox2->SelectionStart = textBox2->Text->Length;
				 textBox2->SelectionLength = 0;
			 }
			 if (e->KeyCode == Keys::Space)
			 {
				 spaceCount++;
				 if (backSlashCount == 2)
				 {
					 displayLabel();
					 if(indexLastSpace == 0)
							label4->Text = mainLabel;
					 else
							label4->Text = subLabel;
					 indexLastSpace = textBox2->Text->Length-1;
				 }
				 backSlashCount = 0;
				 
			 }

			 if (e->KeyCode ==  Keys::Enter)
			 {
				/************************************************************************/
				/* Input and output from the main logic goes here                       */
				/************************************************************************/
				 this->textBox2->AutoCompleteCustomSource->Clear();
				 resetParameters();
				 if (textBox2->Text->Equals("//exit"))
				{
				 this->Close();
				}
				 if (textBox2->Text->Equals("//p"))
				 {
					 if (currentPage > 0)
					 {
						 currentPage--;
						textBox1->Text = pages[currentPage];
						label2Text(currentPage+1);
					 }
				 } 
				 else if ( textBox2->Text->Equals("//n"))
				 {
					 
					 if (currentPage < pages->Count-1)
					 {
						 currentPage++;
						textBox1->Text = pages[currentPage];
						label2Text(currentPage+1);
					 }
				 }
				 int i;
				 
				 cli::array<System::String ^> ^ tempCollection = gcnew cli::array<System::String ^>(10);
				 for ( i = 0; i < 10; i++)
				 {
					 tempCollection[i] = "//" +  stringCollection[i];
				 }

				 // getLineCount()
				 this->textBox2->AutoCompleteCustomSource->AddRange(tempCollection);
				 enableAutoComplete();
				 label4->Text = "";
				 this->textBox2->AutoCompleteSource = System::Windows::Forms::AutoCompleteSource::CustomSource;
				newlineFontSettings();
				firstFocus = true;
			 }
			 
			 if ( e->KeyCode == Keys::OemQuestion)
			 {
				 label4->Text = mainLabel;
				 backSlashCount++;
				 isLastBackslash = true;
				 indexLastSpace = textBox2->Text->Length-1;
			 }
			 else
				 isLastBackslash = false;
			 if ( backSlashCount == 2 && isLastBackslash)
			 {

				 int i;
				 cli::array<System::String ^> ^ tempCollection = gcnew cli::array<System::String ^>(10);
				 for ( i = 0; i < 10; i++)
				 {
					 tempCollection[i] = textBox2->Text +  stringCollection[i];
				 }
				 
				// getLineCount();
				 this->textBox2->AutoCompleteCustomSource->AddRange(tempCollection);
				 this->textBox2->AutoCompleteSource = System::Windows::Forms::AutoCompleteSource::CustomSource;
				 isLastBackslash = false;
			 }
			 
		 }
		 
private: int getLineCount()
		 {
			 int  i, numberOfLines = 0;
			 numberOfLines = textBox1->Lines->Length;
			 for ( i = 0; i < textBox1->Lines->Length; i++ )
			 {
				 if ( textBox1->Lines[i]->Length > 40)
				 {
					 numberOfLines += textBox1->Lines[i]->Length / 40;
				 }
			 }
			 return numberOfLines;
		 }

		 System::Void displayText(StringCollection ^ collection)
		 {
			 int i , numberOfLines = getLineCount();
			 int pageLineCount = 0, pageCount = 0;
			 String ^ temp = "";
			 for ( i = 0; i < textBox1->Lines->Length; i++ )
			 {
				 String ^ currentLine = textBox1->Lines[i];
				 if (	 currentLine->Length > 40)
				 {
					 pageLineCount += currentLine->Length / 40;
				 }
				 pageLineCount++;
				 if (pageLineCount  <= 11 )
				 {
					 temp += currentLine + Environment::NewLine; 
				 }
				 else if( pageLineCount > 11  )
				 {	 
					 collection->Add(temp);
					 temp = "";
					 pageLineCount = 0;
					 pageCount++;
					 i--;
				 }
				 if (i==( textBox1->Lines->Length -2))
				 {
					  collection->Add(temp);
				 }
			 }
			 textBox1->Text = collection[0];
		 }
private: System::Void textBox2_Click(System::Object^  sender, System::EventArgs^  e) {
			 

		 }
private: System::Void Form1_Shown(System::Object^  sender, System::EventArgs^  e) {
			 textBox2->Focus();
			 firstFocus= true;
			 textBox2->SelectionStart = 2;
			 textBox2->SelectionLength = 0;
		 }
private: System::Void resetParameters()
		 {
			 backSlashCount = 2;
			 indexLastSpace = 0;
			 spaceCount = 0;
			 subLabel = "";
			 mainLabel = "";
		 }
private: System::Void label4_Click(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void textBox2_PreviewKeyDown(System::Object^  sender, System::Windows::Forms::PreviewKeyDownEventArgs^  e) {
			 if (e->KeyCode == Keys::Back && textBox2->Text->Length > 2)
			 {
				 String ^ current = textBox2->Text->Substring(textBox2->Text->Length-1,1);
				 if (current->Equals(" "))
				 {
					 spaceCount--;
				 }
			 }
		 }
private: System::Void textBox2_KeyDown(System::Object^  sender, System::Windows::Forms::KeyEventArgs^  e) {
			 
			 String ^ x = textBox2->Text;
			 if (e->KeyCode ==  Keys::Back &&( textBox2->Text->Substring(0,textBox2->SelectionStart)->Equals("//")))
			 {
				 textBox2->Text = "// ";
				 textBox2->SelectionStart = 3;
				 return;
			 }
		 }
private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
		 }

private: System::Void displayLabel()
		 {
			 if (spaceCount == 1)
			 {
				 //assign and display main command
				 String ^ firstWord  = textBox2->Text;
				 if(firstWord->Equals("//show "))
				 {
					 mainLabel = "SHOW: [Task Name] [//date <when>] [//location <where>]"; 
				 } 
				 else if (firstWord->Equals("//edit "))
				 {
					 mainLabel = "EDIT: <Index> [New Name] [//date <New Date>] [//time <New Time>]"+ Environment::NewLine +"          [//location <New Location>] [//priority <New Priority>]";
				 } 
				 else if (firstWord->Equals("//delete "))
				 {
					 mainLabel = "DELETE: <Index>";
				 }
				 else if (firstWord->Equals("//exit "))
				 {
					 mainLabel = "Exit Tempus";
				 }

				 else if(firstWord->Equals("//add "))
				 {
					 mainLabel = "ADD: <Task Name> //date <when> [//location <where>]"+ Environment::NewLine +"          [//location <New Location>] [//priority <New Priority>]";
				 }
				 else
				 {
					 mainLabel = "Invalid command";
				 }
			 }
			 else
			 {
				 String ^ command = textBox2->Text->Substring( indexLastSpace-1 , textBox2->Text->Length- indexLastSpace);
				if( command->Equals("//date"))
				{
					subLabel = "DATE: <Today/Tomorrow/(dd/mm/yyyy)/(dd.mm.yyyy))>";
				}
				else if( command->Equals("//location"))
				{
					subLabel = "LOCATION: <Location>";
				}
				else if( command->Equals("//time"))
				{
					subLabel = "TIME: <HH:MM/HH.MM> <AM/PM> [HH:MM <AM/PM>-HH:MM <AM/PM>]";
				}
				else if( command->Equals("//priority"))
				{
					subLabel = "PRIORITY: [L/M/H]";
				}
				else 
					subLabel = "Invalid command";
				 //get and assign sub command 
			 }
		 }
};
}

